#!/bin/bash

# Configura um roteador
# Matheus Estrela - 12/12/2014

IP=$1
VT=$2

# Dir dos arquivos
SYSCONFS=sysconfs

if [ $# -lt 2 ]; then
  echo "==> Uso: $0 IP VT"
  exit 1
fi

# manda o proxy.sh
scp ${SYSCONFS}/proxy.sh root@$IP:

# configura yum
ssh root@$IP "(source /root/proxy.sh; rpm -ivh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm)"

#instalando a !@#$!#@$@#$@$ do ssh !
ssh root@$IP "source /root/proxy.sh; yum -y install openssh-clients tcpdump iperf man mailx telnet mc"

# configura o postfix
scp ${SYSCONFS}/postfix/main.cf root@$IP:/etc/postfix
ssh root@$IP "(chkconfig postfix on;service postfix restart)"

# NTP
ssh root@$IP "(source /root/proxy.sh; yum -y install ntp)"
scp ${SYSCONFS}/ntp/ntp.conf root@$IP:/etc
ssh root@$IP "(service ntpd restart;chkconfig ntpd on)"

# SNMPd
ssh root@$IP "(source /root/proxy.sh; yum -y install net-snmp.x86_64)"
scp ${SYSCONFS}/snmpd/snmpd.conf root@$IP:/etc/snmpd
ssh root@$IP "(service snmpd restart;chkconfig snmpd on)"

# roteamento
scp ${SYSCONFS}/etc/sysctl.conf root@$IP:/etc

# iptables
ssh root@$IP "(chkconfig iptables off; service iptables stop)"

# NICS
scp ${SYSCONFS}/network/$VT/network root@$IP:/etc/sysconfig
#scp ${SYSCONFS}/network/$VT/ifcfg-eth0 root@$IP:/etc/sysconfig/network-scripts
#scp ${SYSCONFS}/network/$VT/ifcfg-eth1 root@$IP:/etc/sysconfig/network-scripts
#scp ${SYSCONFS}/network/$VT/route-eth1 root@$IP:/etc/sysconfig/network-scripts
scp ${SYSCONFS}/network/$VT/ifcfg-eth0 ${SYSCONFS}/network/$VT/ifcfg-eth1 ${SYSCONFS}/network/$VT/route-eth0 ${SYSCONFS}/network/$VT/route-eth1 root@$IP:/etc/sysconfig/network-scripts

# script_rotas
ssh root@$IP "(mkdir bin; mkdir -p rotas/$VT)"
scp script_rotas.sh root@$IP:bin
scp confs/script_rotas.conf.$VT root@$IP:rotas/$VT/script_rotas.conf
